home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -seriously_amiga- / shareware / programming / e / easyplugins / source / text.e < prev    next >
Text File  |  1997-12-06  |  7KB  |  275 lines

  1.  
  2. /*
  3.  
  4.     text_plugin.e (part OF EasyPLUGINs)
  5.  
  6. */
  7.  
  8. OPT MODULE, PREPROCESS, OSVERSION=37
  9.  
  10. ->> text_plugin: Modules
  11.  
  12. MODULE 'tools/easygui', 'graphics/text', 'tools/ghost',
  13.        'intuition/intuition', 'intuition/screens',
  14.        'graphics/rastport'
  15.  
  16. MODULE 'utility', 'utility/tagitem'
  17.  
  18. -><
  19.  
  20. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  21.  
  22. ->> text_plugin: Definitions
  23. EXPORT OBJECT text_plugin OF plugin PRIVATE
  24.  
  25.     contents:PTR TO CHAR
  26.     highlight
  27.     three_d
  28.     justification
  29.     draw_bar
  30.     font:PTR TO textattr
  31.     disabled
  32.  
  33.     text_width
  34.     text_height
  35.  
  36. ENDOBJECT
  37.  
  38. -> PROGRAMMER_ID | MODULE_ID
  39. ->      $01      |   $02
  40.  
  41. EXPORT ENUM PLA_Text_Text=$81020001,        ->[I.G]
  42.             PLA_Text_Highlight,             ->[ISG]
  43.             PLA_Text_ThreeD,                ->[ISG]
  44.             PLA_Text_Justification,         ->[ISG]
  45.             PLA_Text_DrawBar,               ->[ISG]
  46.             PLA_Text_Font,                  ->[I.G]
  47.             PLA_Text_Disabled               ->[ISG]
  48.  
  49. EXPORT ENUM PLV_Text_JustifyCenter=0,
  50.             PLV_Text_JustifyLeft,
  51.             PLV_Text_JustifyRight
  52.  
  53. -><
  54.  
  55. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  56.  
  57. ->> text_plugin: text()
  58. PROC text(tags:PTR TO tagitem) OF text_plugin
  59.  
  60.     IF utilitybase
  61.  
  62.         self.contents       := GetTagData(PLA_Text_Text, '', tags)
  63.         self.highlight      := GetTagData(PLA_Text_Highlight, FALSE, tags)
  64.         self.three_d        := GetTagData(PLA_Text_ThreeD, FALSE, tags)
  65.         self.font           := GetTagData(PLA_Text_Font, NIL, tags)
  66.         self.justification  := GetTagData(PLA_Text_Justification, PLV_Text_JustifyCenter, tags)
  67.         self.draw_bar       := GetTagData(PLA_Text_DrawBar, FALSE, tags)
  68.         self.disabled       := GetTagData(PLA_Text_Disabled, FALSE, tags)
  69.  
  70.     ELSE
  71.  
  72.         Raise("util")
  73.  
  74.     ENDIF
  75.  
  76. ENDPROC
  77. -><
  78.  
  79. ->> text_plugin: set() & get()
  80.  
  81. PROC set(attr, value) OF text_plugin
  82.  
  83.     SELECT attr
  84.  
  85.         CASE PLA_Text_Highlight
  86.  
  87.             IF self.highlight<>value
  88.  
  89.                 self.highlight:=value
  90.  
  91.                 IF (self.disabled=FALSE) THEN  self.draw(self.gh.wnd)
  92.  
  93.             ENDIF
  94.  
  95.         CASE PLA_Text_ThreeD
  96.  
  97.             IF self.three_d<>value
  98.  
  99.                 self.three_d:=value
  100.  
  101.                 IF (self.disabled=FALSE) THEN  self.draw(self.gh.wnd)
  102.  
  103.             ENDIF
  104.  
  105.         CASE PLA_Text_Justification
  106.  
  107.             IF self.justification<>value
  108.  
  109.                 IF (value >= PLV_Text_JustifyCenter) AND (value <= PLV_Text_JustifyRight)
  110.  
  111.                     self.justification:=value
  112.  
  113.                     IF (self.disabled=FALSE) THEN  self.draw(self.gh.wnd)
  114.  
  115.                 ENDIF
  116.  
  117.             ENDIF
  118.  
  119.         CASE PLA_Text_DrawBar
  120.  
  121.             IF self.draw_bar<>value
  122.  
  123.                 self.draw_bar:=value
  124.  
  125.                 IF (self.disabled=FALSE) THEN  self.draw(self.gh.wnd)
  126.  
  127.             ENDIF
  128.  
  129.         CASE PLA_Text_Disabled
  130.  
  131.             IF self.disabled<>value
  132.  
  133.                 self.disabled:=value
  134.  
  135.                 self.draw(self.gh.wnd)
  136.  
  137.             ENDIF
  138.  
  139.     ENDSELECT
  140.  
  141. ENDPROC
  142.  
  143. PROC get(attr) OF text_plugin
  144.  
  145.     SELECT attr
  146.  
  147.         CASE PLA_Text_Text;             RETURN self.contents, TRUE
  148.         CASE PLA_Text_Highlight;        RETURN self.highlight, TRUE
  149.         CASE PLA_Text_ThreeD;           RETURN self.three_d, TRUE
  150.         CASE PLA_Text_Justification;    RETURN self.justification, TRUE
  151.         CASE PLA_Text_DrawBar;          RETURN self.draw_bar, TRUE
  152.         CASE PLA_Text_Font;             RETURN self.font, TRUE
  153.         CASE PLA_Text_Disabled;         RETURN self.disabled, TRUE
  154.  
  155.     ENDSELECT
  156.  
  157. ENDPROC -1, FALSE
  158.  
  159. -><
  160.  
  161. ->> text_plugin: draw()
  162. PROC draw(win:PTR TO window, font=NIL:PTR TO textattr) OF text_plugin
  163.  
  164.     DEF left_side, right_side, text_start, gap, line_height, justification
  165.  
  166.     IF win
  167.         SetStdRast(win.rport)
  168.  
  169.         Box(self.x, self.y, (self.x+(self.xs-1)), (self.y+(self.ys-1)), 0)
  170.  
  171.         IF self.disabled=FALSE
  172.  
  173.             line_height:=self.y + (self.text_height/2)
  174.  
  175.             left_side:=self.x + 2
  176.             right_side:=self.x + self.xs -3
  177.  
  178.             gap:=6
  179.  
  180.             IF self.font;       font:=self.font
  181.             ELSEIF font=NIL;    font:=win.wscreen.font
  182.             ENDIF
  183.  
  184.             justification:=self.justification
  185.  
  186.             SELECT justification
  187.  
  188.                 CASE PLV_Text_JustifyLeft
  189.  
  190.                     print_text(self, font, left_side, self.y)
  191.                     IF self.draw_bar THEN draw_line((left_side + self.text_width + gap), right_side, line_height)
  192.  
  193.                 CASE PLV_Text_JustifyRight
  194.  
  195.                     IF self.draw_bar THEN draw_line(left_side, (right_side - (self.text_width + gap)), line_height)
  196.                     print_text(self, font, (right_side - self.text_width), self.y)
  197.  
  198.                 DEFAULT
  199.  
  200.                     text_start:=left_side + (((right_side - left_side) - self.text_width) / 2) + 1
  201.  
  202.                     IF self.draw_bar THEN draw_line(left_side, (text_start - gap), line_height)
  203.                     print_text(self, font, text_start, self.y)
  204.                     IF self.draw_bar THEN draw_line((text_start + self.text_width + gap), right_side, line_height)
  205.  
  206.             ENDSELECT
  207.  
  208.         ELSE
  209.  
  210.             ghost(win, self.x, self.y, self.xs, self.ys)
  211.  
  212.         ENDIF
  213.  
  214.     ENDIF
  215.  
  216. ENDPROC
  217. -><
  218.  
  219. ->> text_plugin: min_size() & will_resize()
  220. PROC min_size(font:PTR TO textattr, font_height) OF text_plugin
  221.  
  222.     self.text_width:= IntuiTextLength([1, 0, RP_JAM1, 0, 0,
  223.                                       (IF self.font THEN self.font ELSE font),
  224.                                       self.contents, NIL]:intuitext)
  225.  
  226.     self.text_height:=(IF self.font THEN self.font.ysize ELSE font_height)
  227.  
  228. ENDPROC (self.text_width + 24), (self.text_height + 2)
  229.  
  230. PROC will_resize() OF text_plugin IS COND_RESIZEX
  231.  
  232. -><
  233.  
  234. ->> text_plugin: render()
  235.  
  236. PROC render(font:PTR TO textattr, x, y, xs, ys, win:PTR TO window) OF text_plugin
  237.  
  238.     self.draw(win, font)
  239.  
  240. ENDPROC
  241.  
  242. -><
  243.  
  244. ->> private to text_plugin.draw(): draw_line() & print_text()
  245. PROC draw_line(x1, x2, y)
  246.  
  247.     Line(x1, y, x2, y, 1)
  248.     Line(x1, y+1, x2, y+1, 2)
  249.  
  250. ENDPROC
  251.  
  252. PROC print_text(t:PTR TO text_plugin, font:PTR TO textattr, x, y)
  253.  
  254.     DEF bt_col, ft_col
  255.  
  256.     IF t.highlight
  257.  
  258.         bt_col:=1; ft_col:=2
  259.  
  260.     ELSE
  261.  
  262.         bt_col:=2; ft_col:=1
  263.  
  264.     ENDIF
  265.  
  266.     IF t.three_d THEN PrintIText(stdrast, [bt_col, 0, RP_JAM1, 1, 1, font, t.contents, NIL]:intuitext, x, y)
  267.  
  268.     PrintIText(stdrast, [ft_col, 0, RP_JAM1, 0, 0, font, t.contents, NIL]:intuitext, x, y)
  269.  
  270. ENDPROC
  271. -><
  272.  
  273.  
  274.  
  275.